import { Injectable, NestMiddleware } from '@nestjs/common';
import { NextFunction } from 'express';
import { addSalt , encript } from 'src/utils/encripttion'
@Injectable()
export class HashPasswordMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    // console.log("Request",req.body['password']);
    // 拿到密码进行佳加密
    let userPassword = req.body['password']
    if(userPassword){
      const psalt = addSalt()
      userPassword = encript(userPassword,psalt)
      req.body['password'] = userPassword
      req.body['psalt'] = psalt
    }
    next();
  }
}
 